package org.iipg.service.core.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.iipg.common.data.component.SysUserHolder;
import org.iipg.common.data.dto.UserDto;
import org.iipg.common.data.exception.PhException;
import org.iipg.service.core.prop.PhProperties;
import org.iipg.service.core.util.ConvUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.iipg.service.core.vo.UserVo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhuhy163@163.com
 * @Description
 * @date 2020/12/12 下午2:43
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("sys")
public class SysController {

    private final SysUserHolder sysUserHolder;

    private final PhProperties phProperties;

    @ApiOperation(value = "当前用户", produces = "application/json")
    @GetMapping(value = "/currentUser", produces = {MediaType.APPLICATION_JSON_VALUE})
    public UserVo currentUser() {

        UserDto userDTO = sysUserHolder.getCurrentUser(phProperties.getTokenSecret());

        log.info(JSONUtil.toJsonStr(userDTO));

        UserVo userVo = new UserVo();
        BeanUtil.copyProperties(userDTO, userVo);

        return ConvUtil.convertObject(userVo, UserVo.class);
    }

}
